﻿using Basic.FlowApplication.Interface;
using Basic.FlowCollect;
using Basic.FlowModel.AuditLogItem;
using Basic.FlowRemoteModel;
using Basic.FlowRemoteModel.Application.Model;
using WeDonekRpc.Helper;

namespace Basic.FlowApplication.TimeTask
{
    internal class EnableAuditService : IEnableAuditService
    {
        private readonly IFlowAuditItemLogCollect _ItemLog;
        private readonly ISubmitAuditService _Audit;
        public EnableAuditService ( IFlowAuditItemLogCollect itemLog, ISubmitAuditService audit )
        {
            this._Audit = audit;
            this._ItemLog = itemLog;
        }

        public void StartAudit ()
        {
            StayRunAuditItem[] items = this._ItemLog.GetStayRunItem();
            if ( items.IsNull() )
            {
                return;
            }
            items.ForEach(this._StartAudit);
        }

        private void _StartAudit ( StayRunAuditItem item )
        {
            _ = this._Audit.Submit(item.LogId, new AuditRes
            {
                AuditEmpId = item.EmpId,
                AuditResult = FlowAuditResult.启动,
                ItemId = item.Id
            });
        }
    }
}
